package com.atjg.autocat.service;

import android.annotation.SuppressLint;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

import com.atjg.autocat.main.App;
import com.atjg.autocat.main.SplashActivity;
import com.zhy.baselibrary.utils.Klog;

import java.util.Objects;

public class BootReceiver extends BroadcastReceiver {
    private final String tag = "BootReceiver";
    @SuppressLint("UnsafeProtectedBroadcastReceiver")
    @Override
    public void onReceive(Context context, Intent intent) throws SecurityException {
        Klog.Companion.d(tag, "开机启动指令接收到");
        Objects.requireNonNull(App.Companion.getMHanler()).postDelayed(new Runnable() {
            @Override
            public void run() {
                Intent mainIntent = new Intent(context, (Class<?>) SplashActivity.class);
                context.startActivity(mainIntent);
//                ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
//                List<ActivityManager.RunningTaskInfo> taskInfoList = activityManager.getRunningTasks(100);
//                boolean isTop = false;
//                for (ActivityManager.RunningTaskInfo taskInfo : taskInfoList) {
//                    assert taskInfo.topActivity != null;
//                    if (taskInfo.topActivity.getPackageName().equals("com.atjg.autocat")) {
//                        isTop = true;
//                        activityManager.moveTaskToFront(taskInfo.id, 0);
//                        return;
//                    }
//                }
            }
        }, 8000);

    }
}